package com.sunrise.xdoc.view.order;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;

import org.primefaces.context.RequestContext;

import com.sunrise.xdoc.entity.order.DinhMuc;
import com.sunrise.xdoc.service.IOrderService;
import com.sunrise.xdoc.view.AbstractView;

@ManagedBean
@SessionScoped
public class DinhMucView extends AbstractView<DinhMuc> {
	private static final long serialVersionUID = -8791514005604573786L;

	@ManagedProperty(value = "#{orderService}")
	private IOrderService orderService;

	public void updateDinhMuc(DinhMuc dm) {
		setEditedEntity(dm);
		saveOrUpdate();
	}

	/**
	 * Cân bằng định mức bán và còn lại.
	 */
	public void canBangDinhMuc(DinhMuc dm) {
		dm.setConLai(dm.getDinhMucBan());
		updateDinhMuc(dm);
	}

	/**
	 * Lập định mức ngay.
	 */
	public void lapDinhMucNgay() {
		orderService.canBangDinhMucAll();
	}

	@Override
	protected String getDataModelBeanName() {
		return "dinhMucDataModel";
	}

	@Override
	protected String getDetailPanelViewId() {
		return null;
	}

	@Override
	public void reset() {
		RequestContext.getCurrentInstance().reset("dinhMucListFormId");
	}

	public IOrderService getOrderService() {
		return orderService;
	}

	public void setOrderService(IOrderService orderService) {
		this.orderService = orderService;
	}

}
